/**
 * 适配 autocomplete数据源
 * @author xiufu.wang
 */
export default function applyAdapt(dataSource) {
    dataSource.fetchSuggestions = function (queryString, cb) {
        const opt = dataSource.mergeOption
        const queryFiled = opt.singleQueryField || 'query'
        if (!queryString || queryString.trim() === '') {
            cb([])
        }
        const res = dataSource.shortLoadDatas({ [queryFiled]: queryString }, true)
        if (res.then) {
            res.then((data) => {
                cb(dataSource.handleFormatDatas(data, opt) || [])
            })
        } else {
            cb(dataSource.handleFormatDatas(res,opt) || [])
        }
    }
}